<template>
	<view class="page__bd">
		<view class="weui-panel weui-panel_access">
			<view class="weui-panel__bd">
				<view v-for="(item,index) in newsList" class="weui-media-box weui-media-box_appmsg" hover-class="weui-cell_active"
				 :id="item.id" @tap='onNewsDetailTap'>
					<view class="weui-media-box__hd weui-media-box__hd_in-appmsg">
						<image class="weui-media-box__thumb" :src="item.poster" />
					</view>
					<view class="weui-media-box__bd weui-media-box__bd_in-appmsg">
						<view class="weui-media-box__title">{{item.title}}</view>
						<view class="weui-media-box__desc">{{item.abstract}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import app from '@/App.vue';
	import {
		GYZJMODEL as gyzjModel
	} from '@/utils/gyzjModel.js'
	export default {
		data() {
			return {
				newsList: [],
				page: 1,
				pageCount: 1,
			}
		},
		onLoad(options) {
			const id = options.id;
			console.log('onLoad执行news-list',id);
			this.getNewsList(id, 1,'');
			if (id == 3) {
				uni.setNavigationBarTitle({
					title: '资讯列表',
				})
				return
			}
			if (id == 1) {
				uni.setNavigationBarTitle({
					title: '使用指南',
				})
				return
			}
		},
		methods: {
			getNewsList(id, page, loadMore) {
				console.log('进来new-list开始');
				uni.showLoading({
					title: '加载中',
				});
				gyzjModel.prototype.getNewsList(id,page,loadMore).then(data=>{
					console.log('data的new-list值',data);
					switch (data.code) {
						case 1:
							uni.hideLoading();
							let newsList = this.newsList;
							if (loadMore) {
						
								newsList = newsList.concat(data.data.data);
							} else {
	
								newsList = data.data.data;
							}
							this.newsList = newsList;
							this.pageCount = data.data.page_count;
					
							break;
						default:
							uni.hideLoading();
							uni.showToast({
								title: data.message,
								icon: 'none',
							})
					}
				});
			},
			onNewsDetailTap: function (e) {
			      let id = e.currentTarget.id;
			      console.log("hah ")
			      uni.navigateTo({
			          url: '../news-detail/news-detail?id=' + id,
			      })
			  }
		}
	}
</script>

<style>
	@import url("../../../static/style/app.css");
	.page__bd {
	    padding-bottom: 0;
	    min-height:100vh;
	    background-color:#fff;
	}
</style>
